package com.lxyk.sgq.config;


import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;


@Configuration
@MapperScan("com.lxyk.sgq.dao")
@EnableTransactionManagement
public class MyBatisPlusConfig {

    @Autowired
    private OptimisticLockerInnerInterceptor lockerInterceptor;

    @Autowired
    private PaginationInnerInterceptor pageInterceptor;

    /*
     *   注册自动填充日期处理器到Spring容器
     * */
    @Bean("myMetaObjectHandler")
    public MetaObjectHandler createMetaObjectHandler(){
        return new MyMetaObjectHandler();
    }
    /**
     * 注册插件到spring容器
     */
    @Bean("interceptors")
    public MybatisPlusInterceptor interceptors() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        //往插件集合里放了一个乐观锁的插件
        interceptor.addInnerInterceptor(lockerInterceptor);
        //往插件集合里放了一个分页的插件
        interceptor.addInnerInterceptor(pageInterceptor);
        return interceptor;
    }



}
